import javax.swing.plaf.BorderUIResource;
//实现10000+10000正确显示20000
//注意解除优化volatile还有对里面的操作加锁
public class Demo1 {
    public static volatile int count=0;
    public static  Object locker=new Object();
    public static void main(String[] args) throws InterruptedException {

        Thread thread1=new Thread(()->{
            for (int i = 0; i < 10000; i++) {
                synchronized (locker) {
                    count++;
                }
            }
        });

        Thread thread2=new Thread(()->{

            for (int i = 0; i < 10000; i++) {
                synchronized (locker) {
                    count++;
                }
            }
        });

        thread1.start();
        thread2.start();
        thread1.join();
        thread2.join();
        System.out.println(count);
    }
}
